package com.perfma.xtest.tool;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * 邮件工具
 * 基于spring-boot-starter-mail
 *
 * @author: junhui.si
 * @date: 2020-09-27 10:47
 **/
@Component
public class EmailHelper {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    public void send() throws MessagingException {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject("这是标题");
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo("1163543584@qq.com");
        simpleMailMessage.setText("这是内容");
        javaMailSender.send(simpleMailMessage);
    }
}
